﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Business.Abstract;
using DataAccess.Repository;
using DataAccess.NHibernateHelper;
using Domain.Entity;
using log4net;

namespace Business.Service
{
    public class InvoiceServiceImpl : IInvoiceService
    {
        ILog log = LogManager.GetLogger("InvoiceServiceImpl");
        InvoiceRepository invoiceRepo;

        public InvoiceServiceImpl()
        {
            invoiceRepo = new InvoiceRepository(FluentNHibernateHelper.GetContext());
        }

        public IList<Invoice> GetAllInvoices()
        {
            return invoiceRepo.List().Where(x => x.IsDeleted == false).ToList();
        }

        public Invoice GetInvoiceById(long id)
        {
            return invoiceRepo.List().Where(x => x.IsDeleted == false).ToList().Where(x=>x.ID == id).First();
        }
      
        public void DeleteInvoice(Invoice invoice)
        {
            invoiceRepo.Delete(invoice);
            invoiceRepo.Commit();
        }

        public IList<Invoice> GetAllInvoices(DateTime fromDate, DateTime toDate)
        {
            return invoiceRepo.GetAllInvoices(fromDate, toDate);
        }

        public IList<Invoice> GetAllInvoices(long customerID, DateTime fromDate, DateTime toDate)
        {
            return invoiceRepo.GetAllInvoices(customerID, fromDate, toDate);
        }
    }
}
